package org.example.wumeng.pojo;

import java.io.Serializable;

public class Result<T> implements Serializable {
    private Integer code;
    private String message;
    private T data;
    private Long total;

    public Result() {
    }

    public Result(Integer code, String message, T data, Long total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    // 成功响应
    public static <T> Result<T> success() {
        return new Result<>(200, "操作成功", null, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200, "操作成功", data, null);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(200, message, data, null);
    }

    public static <T> Result<T> success(T data, Long total) {
        return new Result<>(200, "查询成功", data, total);
    }

    // 失败响应
    public static <T> Result<T> error(String message) {
        return new Result<>(500, message, null, null);
    }

    public static <T> Result<T> error(Integer code, String message) {
        return new Result<>(code, message, null, null);
    }

    // 常用状态码响应
    public static <T> Result<T> unauthorized(String message) {
        return new Result<>(401, message, null, null);
    }

    public static <T> Result<T> badRequest(String message) {
        return new Result<>(400, message, null, null);
    }

    public static <T> Result<T> notFound(String message) {
        return new Result<>(404, message, null, null);
    }

    // getter和setter方法
    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }


}